package org.voidness.oje2d.gui.docks;

import org.voidness.oje2d.GLColor;
import org.voidness.oje2d.GLImage;
import org.voidness.oje2d.gui.Widget;

public class VerticalDockEdge extends Widget implements DockEdge {
    private GLImage top = null;

    private GLImage bottom = null;

    private GLImage back = null;

    private GLColor color = null;

    public VerticalDockEdge(int mWidth, int mHeight) {
        super(mWidth, mHeight);
        color = GLColor.WHITE;
    }

    public VerticalDockEdge(int xPos, int yPos, int mWidth, int mHeight) {
        super(xPos, yPos, mWidth, mHeight);
        color = GLColor.WHITE;
    }

    public void setImages(GLImage[] mEdges, String mBack) {
        top = mEdges[0];
        bottom = mEdges[1];
        int lateralHeight = height - (top.getHeight() + bottom.getHeight());
        back = new GLImage(mBack, top.getWidth(), lateralHeight, false);
    }

    public void setColor(GLColor mColor) {
        color = mColor;
    }

    public void draw(GLColor mColor) {
        // Only draw if all images are set
        if (top == null || bottom == null || back == null)
            return;

        top.setColor(color);
        bottom.setColor(color);
        back.setColor(color);

        // Draw only if visible
        if (!visible)
            return;

        int drawX = xPos;
        int drawY = yPos;

        top.draw(drawX, drawY, color.getAlpha());
        drawY += top.getHeight();
        back.draw(drawX, drawY, color.getAlpha());
        drawY += back.getHeight();
        bottom.draw(drawX, drawY, color.getAlpha());
    }
}
